package com.pinc.exam;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Category_Adapter extends MyBaseAdapter<Category_Class> {

	public static final int ALL_ID = -1;
	public static final int MODE_VIEW = 0;
	public static final int MODE_TEST = 1;
	public int mMode;

	public Category_Adapter(Context context, int mode) {
		super(context);
		items = new ArrayList<Category_Class>();
		mMode = mode;
	}

	public Category_Adapter(Context context) {
		this(context, MODE_VIEW);
	}

	public String getCategoryName(int position)
	{
		return items.get(position).name;
	}

	public void addAll(int total)
	{
		Category_Class cc = new Category_Class(ALL_ID, mcontext.getResources().getString(R.string.str_all_questions), total);
		add(cc);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;

		if ( mMode == MODE_VIEW)
		{
			view = inflater.inflate(R.layout.category_item, null);

			TextView tv_q = (TextView) view.findViewById(R.id.textView1);
			TextView tv_n = (TextView) view.findViewById(R.id.textView2);
			tv_q.setText(items.get(position).name);
			tv_n.setText("(" + items.get(position).total + ")");
		}
		else
		{
			view = new CheckedListItem(mcontext);
			((CheckedListItem)view).setText1(items.get(position).name);
			((CheckedListItem)view).setText2(String.format("(%d)",items.get(position).total));
		}
		return view;
	}

}
